package com.gitee.fastmybatis.spring.boot.autoconfigure.multi;

import com.gitee.fastmybatis.spring.boot.autoconfigure.MybatisProperties;

import javax.sql.DataSource;
import java.util.Objects;

public class DataSourceProp {
    /**
     * 数据源名称
     */
    private String name;
    /**
     * 数据源链接
     */
    private String url;
    /**
     * 驱动名称
     */
    private String driverClassName;
    /**
     * 数据源类型,默认为HikariDataSource
     */
    private Class<? extends DataSource> type;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;

    /**
     * 从连接池获取连接时最大等待时间, 单位毫秒, 默认值 30秒, 至少 250ms
     */
    private long connectionTimeout;
    /**
     * 检测连接是否有效的超时时间，单位毫秒, 默认 5000ms, 最小 250ms, 不能大于connectionTimeout
     */
    private long validationTimeout;
    /**
     * 连接可以在池中的最大闲置时间, 单位毫秒, 至少 10s, 默认 10 分钟, 0 表示永不超时, 该配置不能大于maxLifetime
     */
    private long idleTimeout;
    /**
     * 连接泄露检测的最大时间, 默认 0, 最低 2000毫秒; 也就是说, 连接从拿出连接池到还回连接池的总时间, 不能超出这个时间,超出的话就判定为泄露
     */
    private long leakDetectionThreshold;
    /**
     * 连接最大存活时间, 单位毫秒, 最小允许值30000 ms, 默认30分钟, 推荐设置的比数据库的 wait_timeout 小几分钟
     */
    private long maxLifetime;
    /**
     * 连接池中可以保留连接的最大数量, 比如: 100, 则连接池中的连接不能超过 100 个
     */
    private int maxPoolSize;
    /**
     * 最小空闲连接数量, 默认 10 个, 也就是说, 连接池中最多可以保留 10 个空闲的连接, 多的会被关闭
     */
    private int minIdle;

    /**
     * mybatis配置
     */
    private MybatisProperties mybatis;

    /**
     * 主数据源,只能指定一个
     */
    private Boolean main = false;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Class<? extends DataSource> getType() {
        return type;
    }

    public void setType(Class<? extends DataSource> type) {
        this.type = type;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public long getConnectionTimeout() {
        return connectionTimeout;
    }

    public void setConnectionTimeout(long connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public long getValidationTimeout() {
        return validationTimeout;
    }

    public void setValidationTimeout(long validationTimeout) {
        this.validationTimeout = validationTimeout;
    }

    public long getIdleTimeout() {
        return idleTimeout;
    }

    public void setIdleTimeout(long idleTimeout) {
        this.idleTimeout = idleTimeout;
    }

    public long getLeakDetectionThreshold() {
        return leakDetectionThreshold;
    }

    public void setLeakDetectionThreshold(long leakDetectionThreshold) {
        this.leakDetectionThreshold = leakDetectionThreshold;
    }

    public long getMaxLifetime() {
        return maxLifetime;
    }

    public void setMaxLifetime(long maxLifetime) {
        this.maxLifetime = maxLifetime;
    }

    public int getMaxPoolSize() {
        return maxPoolSize;
    }

    public void setMaxPoolSize(int maxPoolSize) {
        this.maxPoolSize = maxPoolSize;
    }

    public int getMinIdle() {
        return minIdle;
    }

    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }

    public MybatisProperties getMybatis() {
        return mybatis;
    }

    public void setMybatis(MybatisProperties mybatis) {
        this.mybatis = mybatis;
    }

    public Boolean getMain() {
        return main;
    }

    public void setMain(Boolean main) {
        this.main = main;
    }

    @Override
    public String toString() {
        return "DataSourceProp{" +
                "url='" + url + '\'' +
                ", driverClassName='" + driverClassName + '\'' +
                ", type='" + type + '\'' +
                ", main='" + main + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object object) {
        if (object == null || getClass() != object.getClass()) return false;
        DataSourceProp that = (DataSourceProp) object;
        return Objects.equals(url, that.url) && Objects.equals(username, that.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(url, username);
    }
}
